﻿using System;
using Epm.AppLogic.Framework;
using msBsc.Xsd.DataTds;
using System.Data;
using msBsc.AppLogic.DataAlc.cls;
using msBsc.Cls;

namespace msBsc.AppLogic.DataAlc
{
    public class CBizViolationRecord : CustBizObject
    {
        private CDmDjkViolationRecord m_CDmDjkViolationRecord = new CDmDjkViolationRecord();
        private CDmDjkViolationRecord oDmDjkViolationRecord
        {
            get { return m_CDmDjkViolationRecord; }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public CBizViolationRecord()
            : base()
        {
            this.DataObj = new CDbAccess();
            this.DataObj.Init(this.m_CDmDjkViolationRecord.DJK_VIOLATION_RECORD);
            this.TableName = this.DataObj.TableName;
            this.DataObj.KeyField = this.DataObj.Fields["VIOLATION_ID"];
        }

        /// <summary>
        /// 新增记录前的处理
        /// </summary>
        /// <param name="drw">新增数据行</param>
        /// <returns>true/false</returns>
        /// <remarks>
        /// 生成ID值
        /// </remarks>
        protected override bool BeforeRowAdded(DataRow drw)
        {
            if (drw[this.KeyFieldName].ToString().Length < 10)
            {
                drw[this.KeyFieldName] = this.DataObj.NewID();
            }
            return true;
        }

        protected override bool BeforeRowDeletedR(DataRow drw)
        {
            //using (msBsc.AppLogic.DataAlc.CBizShpPageColumn objtem = new CBizShpPageColumn())
            //{
            //    DataSet ds = objtem.SelectByPageNo(this.GetRowStr(drw, KeyFieldName));
            //    for (int i = ds.Tables[0].Rows.Count - 1; i >= 0; i--)
            //    {
            //        ds.Tables[0].Rows[i].Delete();
            //    }
            //    objtem.Update(ds);
            //} 
            return true;
        }

        protected override bool AfterRowAdded(DataRow drw)
        {
            return true;
        }

        protected override bool AfterRowModified(DataRow drw)
        {
            return true;
        }

        protected override bool AfterRowDeletedR(DataRow drw)
        {
            return true;
        }


        /// <summary>
        /// 获取地接客 是否有 未处理 违约记录
        /// </summary>
        /// <param name="djkid">用户id</param>
        /// Author:蒲崇彬
        /// Creation date:2015-6-17
        public bool IsViolationRecord(string userid)
        {
            if (string.IsNullOrEmpty(userid))
            {
                return true;
            }
            CDbParmCollection parmCollection = new CDbParmCollection();
            parmCollection.Add(new CDbParm("userid", ParameterDirection.Input, EDbType.String, 36, userid));

            DataSet ds = this.DataObj.QueryBySQL(@"SELECT TOP(1)* FROM DJK_VIOLATION_RECORD WHERE VIOLATION_HANDLE_STATUS=0 AND VIOLATION_USER_ID=@userid", parmCollection);

            if (ds == null || ds.Tables[0].Rows.Count < 1)
            {
                return false;
            }
            return true;
        }
    }
}
